package com.project.controller;

import com.project.bean.PrimaryPostBean;
import com.project.bean.ReplyBean;
import com.project.bean.UserBean;
import com.project.service.IReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("reply")
public class ReplyController {
    @Autowired
    private IReplyService service;

    @RequestMapping("add")
    public String addReply(ReplyBean reply, int primaryId, HttpServletRequest request){
        PrimaryPostBean primary = new PrimaryPostBean();
        primary.setId(primaryId);
        reply.setPrimary(primary);

        //从session中取出登陆用户对象
        UserBean user =  (UserBean) request.getSession().getAttribute("loginUser");
        reply.setUser(user);

        service.add(reply);
        return "ok";
    }
}
